package org.example.javachatroom.controller;

import org.example.javachatroom.mapper.MessageMapper;
import org.example.javachatroom.model.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.Collections;
import java.util.List;

@RestController
public class MessageController {
    @Autowired
    private MessageMapper messageMapper;

    @GetMapping("/message")
    @ResponseBody
    public Object getMessage(int sessionId){
        List<Message> messages = messageMapper.getMessageBySessionId(sessionId);
        //针对查询结果，进行逆置操作，毕竟界面上需要二点是按照时间升序排序的消息，此处得到的是降序排序的消息
        Collections.reverse(messages);
        return messages;
    }
}
